//
//  WCProject.h
//  WabbitCode
//
//  Created by William Towe on 1/22/09.
//  Copyright 2009 Revolution Software. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#import "WCTabViewContextProtocol.h"
#import "WCBuildTarget.h"


// project settings keys
extern NSString *kWCProjectPrefsProjectWindowFrameKey;
extern NSString *kWCProjectPrefsProjectOutlineViewExpandedItemIndexPathStringsKey;
extern NSString *kWCProjectPrefsProjectFileTableViewSortDescriptorDictionariesKey;
extern NSString *kWCProjectPrefsProjectLeftVerticalSplitViewDividerPositionKey;
extern NSString *kWCProjectPrefsProjectRightVerticalSplitViewDividerPositionKey;
extern NSString *kWCProjectPrefsProjectHorizontalSplitViewDividerPositionKey;
extern NSString *kWCProjectPrefsProjectOutlineViewSelectedRowIndexesKey;
extern NSString *kWCProjectPrefsProjectOpenFileNamesKey;
extern NSString *kWCProjectPrefsProjectSelectedOpenFileNameKey;

extern NSString *kWCProjectPrefsProjectFileTableViewAutosaveDictionaryKey;
extern NSString *kWCProjectPrefsProjectErrorsAndWarningsTableViewAutosaveDictionaryKey;
extern NSString *kWCProjectPrefsProjectBookmarksTableViewAutosaveDictionaryKey;
extern NSString *kWCProjectPrefsProjectSymbolsTableViewAutosaveDictionaryKey;

extern NSString *kWCProjectPrefsProjectCurrentTextFileSymbolsTableViewSortDescriptorDictionariesKey;
extern NSString *kWCProjectPrefsProjectSymbolsTableViewSortDescriptorsDictionariesKey;
extern NSString *kWCProjectPrefsProjectBookmarksTableViewSortDescriptorsDictionariesKey;

// toolbar identifiers
extern NSString *kWCProjectToolbarSearchIdentifier;
extern NSString *kWCProjectToolbarBuildIdentifier;
extern NSString *kWCProjectToolbarGetInfoIdentifier;
extern NSString *kWCProjectToolbarProjectWindowIdentifier;
extern NSString *kWCProjectToolbarProjectOverviewIdentifier;
extern NSString *kWCProjectToolbarCountCodeIdentifier;
extern NSString *kWCProjectToolbarBuildResultsWindowIdentifier;
extern NSString *kWCProjectToolbarFindInProjectWindowIdentifier;
extern NSString *kWCProjectToolbarDebuggerWindowIdentifier;
extern NSString *kWCProjectToolbarBuildAndDebugIdentifier;
extern NSString *kWCProjectToolbarBuildAndRunIdentifier;

// notifications
extern NSString *kWCProjectActiveBuildTargetDidChangeNotification;
extern NSString *kWCProjectActiveBuildConfigurationDidChangeNotification;

@class PSMTabBarControl, WCProjectGroup, WCBuildTargetsGroup, WCGroup, WCTextFile, WCProjectFileDetailViewController, WCTextView, WCErrorsAndWarningsGroup, WCFile, WCProjectBuildStatusTextField, WCBuildMessage, WCBuildTarget, WCFindInProjectWindowController, WCFindResult,WCBuildResultsWindowController,WCBookmarksGroup,WCBuildProductsGroup,WCTextFileWindowController;

@interface WCProject : NSDocument <WCTabViewContext> {
	IBOutlet PSMTabBarControl *_psmTabBarControl;
	IBOutlet NSOutlineView *_projectOutlineView;
	IBOutlet NSTabView *_tabView;
	IBOutlet WCProjectBuildStatusTextField *_projectBuildStatusTextField;
	IBOutlet NSTextField *_projectStatusTextField;
	IBOutlet NSSplitView *_verticalSplitView;
	IBOutlet NSSplitView *_horizontalSplitView;
	IBOutlet NSPopUpButton *_projectOutlineViewAddButton;
	IBOutlet NSPopUpButton *_projectOutlineViewActionButton;
	IBOutlet NSPopUpButton *_projectTextViewActionButton;
	IBOutlet NSButton *_lineColumnButton;
	IBOutlet NSImageView *_leftSplitterHandleImageView;
	IBOutlet NSImageView *_rightSplitterHandleImageView;
	
	IBOutlet NSView *_swapView;
	IBOutlet NSView *_fileView;
	IBOutlet NSTableView *_fileTableView;
	IBOutlet NSView *_errorsAndWarningsView;
	IBOutlet NSTableView *_errorsAndWarningsTableView;
	IBOutlet NSView *_bookmarksView;
	IBOutlet NSTableView *_bookmarksTableView;
	IBOutlet NSView *_projectSymbolsView;
	IBOutlet NSTableView *_projectSymbolsTableView;
	IBOutlet NSTableView *_currentTextFileSymbolsTableView;
	
	NSMutableArray *_projectGroups;
	NSCountedSet *_openTextFiles;
	NSMutableSet *_textFiles;
	NSMutableDictionary *_projectPreferences;
	NSArray *_currentTextFileSymbols;
	NSMutableSet *_projectLabels;
	NSMutableSet *_projectEquates;
	NSMutableSet *_projectDefines;
	NSMutableSet *_projectMacros;
	NSView *_currentSwapView;
	WCProjectGroup *_projectGroup;
	WCBuildTargetsGroup *_buildTargetsGroup;
	WCErrorsAndWarningsGroup *_errorsAndWarningsGroup;
	WCBookmarksGroup *_bookmarksGroup;
	WCBuildProductsGroup *_buildProductsGroup;
	NSArray *_projectSymbolsArray;
	
	NSArray *_files;
	NSArray *_errorsAndWarnings;
	NSArray *_bookmarks;
	NSArray *_buildStatusImagesAndStrings;
	NSString *_projectInfoString;
	
	WCBuildTarget *_activeBuildTarget;
	WCBuildConfiguration *_activeBuildConfiguration;
	NSTask *_buildTask;
	NSMutableArray *_targets;
	NSMutableArray *_steps;
	WCBuildMessage *_rootBuildMessage;
	NSString *_buildProductsDirectoryPath;
	NSArray *_buildProductsOutputFilePaths;
	
	NSSearchField *_projectSearchField;
	
	WCFindInProjectWindowController *_findInProjectWindowController;
	WCBuildResultsWindowController *_buildResultsWindowController;
	NSMutableSet *_buildTargetGetInfoWindowControllers;
	NSMutableSet *_fileGetInfoWindowControllers;
	NSMutableSet *_textFileWindowControllers;
	
	BOOL _building;
	BOOL _shouldIgnoreChanges;
	BOOL _shouldRecacheProjectLabels;
	BOOL _shouldRecacheProjectEquates;
	BOOL _shouldRecacheProjectDefines;
	BOOL _shouldRecacheProjectMacros;
	BOOL _shouldRecacheProjectSymbolsArray;
	BOOL _shouldRecacheTextFiles;
	BOOL _shouldAllowEmptyFileDetailTableView;
	BOOL _shouldRunAfterBuilding;
	BOOL _shouldDebugAfterBuilding;
	BOOL _waitingForModalAlertReply;
}

@property (readwrite, assign, getter=isBuilding) BOOL building;
@property (readwrite, assign) BOOL shouldIgnoreChanges;
@property (readwrite, assign) BOOL shouldRecacheTextFiles;
@property (readwrite, assign) BOOL shouldRecacheProjectLabels;
@property (readwrite, assign) BOOL shouldRecacheProjectEquates;
@property (readwrite, assign) BOOL shouldRecacheProjectDefines;
@property (readwrite, assign) BOOL shouldRecacheProjectMacros;
@property (readwrite, assign) BOOL shouldRecacheProjectSymbols;
@property (readwrite, assign) BOOL shouldRecacheProjectSymbolsArray;
@property (readwrite, assign) BOOL shouldAllowEmptyFileDetailTableView;
@property (readwrite, assign) BOOL shouldRunAfterBuilding;
@property (readwrite, assign) BOOL shouldDebugAfterBuilding;
@property (readwrite, assign, getter=isWaitingForModalAlertReply) BOOL waitingForModalAlertReply;

@property (readwrite, assign) WCBuildTarget *activeBuildTarget;
@property (readwrite, assign) WCBuildConfiguration *activeBuildConfiguration;
@property (readwrite, retain) NSTask *buildTask;
@property (readonly) NSMutableArray *targets;
@property (readonly) NSMutableArray *steps;
@property (readwrite, retain) WCBuildMessage *rootBuildMessage;
@property (readwrite, copy) NSString *buildProductsDirectoryPath;
@property (readwrite, retain) NSArray *buildStatusImagesAndStrings;
@property (readwrite, retain) NSArray *buildProductsOutputFilePaths;

@property (readwrite, assign) NSView *currentView;
@property (readonly) NSMutableArray *projectGroups;
@property (readonly) PSMTabBarControl *psmTabBarControl;
@property (readonly) NSOutlineView *projectOutlineView;
@property (readonly) WCProjectGroup *projectGroup;
@property (readwrite, retain) NSMutableDictionary *projectPreferences;
@property (readonly) NSWindow *projectWindow;
@property (readonly) NSSplitView *leftVerticalSplitView;
@property (readonly) NSSplitView *horizontalSplitView;
@property (readonly) NSString *projectPreferencesPath;
@property (readonly) NSString *projectDataPath;
@property (readonly) NSTreeController *projectTreeController;
@property (readonly) WCBuildTargetsGroup *buildTargetsGroup;
@property (readonly) NSTreeNode *selectedFileNode;
@property (readonly) NSArray *selectedNodes;
@property (readonly) NSUInteger insertionIndexForBuildTargetsGroup;
@property (readonly) NSTreeNode *selectedBuildConfigurationNode;
@property (readwrite, retain) NSArray *files;
@property (readonly) NSTableView *fileDetailTableView;
@property (readonly) NSArrayController *fileDetailArrayController;
@property (readonly) NSArray *selectedRepresentedObjects;
@property (readonly) WCTextView *currentTextView;
@property (readonly) NSString *projectName;
@property (readonly) NSString *projectFolderPath;
@property (readonly) NSString *absoluteFilePathOfFirstTextFile;
@property (readonly) WCProjectBuildStatusTextField *projectBuildStatusTextField;
@property (readonly) NSObject <WCTabViewContext> *currentTabViewContext;
@property (readonly) NSArray *unsavedTextFiles;
@property (readonly) NSCountedSet *openTextFiles;
@property (readwrite, copy) NSString *projectInfoString;
@property (readonly) NSTableView *errorsWarningsTableView;
@property (readwrite, retain) NSArray *errorsAndWarnings;
@property (readonly) WCErrorsAndWarningsGroup *errorsAndWarningsGroup;
@property (readonly) NSUInteger insertionIndexForIncludeDirectoryGroup;
@property (readonly) WCFindInProjectWindowController *findInProjectWindowController;
@property (readonly) WCFindInProjectWindowController *findInProjectWindowControllerDontCreate;
@property (readwrite, retain) NSArray *currentTextFileSymbols;
@property (readonly) NSTableView *projectLabelsTableView;
@property (readonly) NSSet *projectLabels;
@property (readonly) NSSet *projectEquates;
@property (readonly) NSSet *projectDefines;
@property (readonly) NSSet *projectMacros;
@property (readonly) NSSet *projectSymbolsForAutocomplete;
@property (readonly) WCBuildResultsWindowController *buildResultsWindowController;
@property (readonly) WCBuildResultsWindowController *buildResultsWindowControllerDontCreate;
@property (readwrite, retain) NSArray *projectSymbolsArray;
@property (readonly) NSMutableSet *buildTargetGetInfoWindowControllers;
@property (readonly) NSMutableSet *fileGetInfoWindowControllers;
@property (readonly) NSMutableSet *textFiles;
@property (readonly) NSArray *allTabViewContexts;
@property (readonly) WCBookmarksGroup *bookmarksGroup;
@property (readwrite, retain) NSArray *bookmarks;
@property (readonly) NSSearchField *projectSearchField;
@property (readonly) WCBuildProductsGroup *buildProductsGroup;
@property (readonly) NSMutableSet *textFileWindowControllers;

- (WCFile *)fileMatchingAbsoluteFilePath:(NSString *)absoluteFilePath;
- (WCGroup *)groupForNewFileInsertionAndInsertionIndex:(NSUInteger *)insertionIndex;
- (void)updateSwapView;
- (void)updateAllTabViewContexts;
- (BOOL)buildTargetExistsWithModel:(WCBTModel)model output:(WCBTOutputType)output;
- (BOOL)canDeleteObjects:(NSArray *)objects;
- (void)deleteObjects:(NSArray *)objects moveFilesToTrash:(BOOL)moveFilesToTrash;
- (void)removeAllBuildErrorsAndWarnings;
- (void)removeAllBuildMessages;
- (id)showGetInfoWindowForItem:(id)item;
- (void)cycleToNextFirstResponder;
- (void)cycleToPreviousFirstResponder;
- (WCTextFileWindowController *)createSeparateEditorForTextFile:(WCTextFile *)textFile;

- (NSTabViewItem *)addTabViewItemForTextFile:(WCTextFile *)textFile inTabViewContext:(NSObject <WCTabViewContext> *)context;
- (BOOL)canRemoveTabViewItem:(NSTabViewItem *)tabViewItem inTabViewContext:(NSObject <WCTabViewContext> *)context;
- (void)removeTabViewItem:(NSTabViewItem *)tabViewItem inTabViewContext:(NSObject <WCTabViewContext> *)context saveTextFile:(BOOL)flag;
- (void)removeAllTabViewItemsInTabViewContext:(NSObject <WCTabViewContext> *)context;
- (void)removeAllTabViewItemsForTextFile:(WCTextFile *)textFile;

// this must be called before an NSTabViewItem is removed from its NSTabView
- (void)unbindTabViewItem:(NSTabViewItem *)tabViewItem inTabViewContext:(NSObject <WCTabViewContext> *)context;
- (void)unbindAllTabViewItemsInTabViewContext:(NSObject <WCTabViewContext> *)context;

- (BOOL)selectTabViewItemWithIdentifier:(WCFile *)file inTabViewContext:(NSObject <WCTabViewContext> *)context;

- (IBAction)newBuildConfigurationAction:(id)sender;
- (IBAction)openInSeparateEditorAction:(id)sender;
- (IBAction)buildProductsAction:(id)sender;
- (IBAction)searchProjectAction:(id)sender;
- (IBAction)delete:(id)sender;
- (IBAction)renameAction:(id)sender;
- (IBAction)addToProjectAction:(id)sender;
- (IBAction)newGroupAction:(id)sender;
- (IBAction)groupAction:(id)sender;
- (IBAction)ungroupAction:(id)sender;
- (IBAction)openWithFinderAction:(id)sender;
- (IBAction)revealInFinderAction:(id)sender;
- (IBAction)getInfoAction:(id)sender;
- (IBAction)projectAction:(id)sender;
- (IBAction)newBuildStepAction:(id)sender;
- (IBAction)buildAction:(id)sender;
- (IBAction)buildAndRunAction:(id)sender;
- (IBAction)buildAndDebugAction:(id)sender;
- (IBAction)buildResultsAction:(id)sender;
- (IBAction)consoleOutputAction:(id)sender;
- (IBAction)fileDetailAction:(id)sender;
- (IBAction)cleanAction:(id)sender;
- (IBAction)cleanAllAction:(id)sender;
- (IBAction)stopAction:(id)sender;
- (IBAction)nextTabAction:(id)sender;
- (IBAction)previousTabAction:(id)sender;
- (IBAction)revealInGroupTreeAction:(id)sender;
- (IBAction)findInProjectAction:(id)sender;
- (IBAction)splitEditorAction:(id)sender;
- (IBAction)searchAction:(id)sender;
- (IBAction)makeActiveTargetAction:(id)sender;
- (IBAction)countCodeAction:(id)sender;
@end
